package Texas.Test;

import Texas.Player;
import org.junit.*;

public class PlayerTest {
	private Player player;
	
	@Before public void setUp() throws Exception {
		player = new Player("Test");
		player.setChips(1000);
	}

	@Test public void testCondition1() {
		int minDediction = 20;
		boolean exception = false;
		
		try {
			player.call(minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(!exception && player.getDediction() == 20 &&
				player.getChips() == 980);
		
		player.setChips(1000);
		player.clearDediction();
		player.clearStates();
		exception = false;
		
		try {
			player.raise(200, minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(!exception && player.hasRaised() &&
				player.getDediction() == 200 && player.getChips() == 800);
		
		player.setChips(1000);
		player.clearDediction();
		player.clearStates();
		exception = false;

		try {
			player.allIn(minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(!exception && player.isAllIn() && 
				player.hasRaised() && player.getChips() == 0 &&
				player.getDediction() == 1000);
	}

	
	@Test public void testCondition2() {
		int minDediction = 0;
		boolean exception = false;
		
		try {
			player.call(minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(exception);
		exception = false;

		try {
			player.raise(200, minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(!exception && player.hasRaised() &&
				player.getDediction() == 200 && player.getChips() == 800);
		player.setChips(1000);
		player.clearDediction();
		player.clearStates();
		exception = false;

		try {
			player.allIn(minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(!exception && player.isAllIn() && 
				player.hasRaised() && player.getChips() == 0 &&
				player.getDediction() == 1000);
	}
	
	@Test public void testCondition3() {
		int minDediction = 1050;
		boolean exception = false;
		
		try {
			player.call(minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(exception);
		exception = false;

		try {
			player.raise(1100, minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(exception);
		exception = false;

		try {
			player.allIn(minDediction);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(!exception && player.isAllIn() && 
				player.getChips() == 0 && player.getDediction() == 1000);
		exception = false;
	}
	
	@Test public void testCondition4() {
		boolean exception = false;
		
		try {
			player.allIn(200);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(!exception);
		exception = false;
		
		try {
			player.call(200);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(exception);
		exception = false;

		try {
			player.raise(500, 200);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(exception);
		exception = false;
	
		try {
			player.allIn(200);
		} catch (Exception e) {
			exception = true;
		}
		Assert.assertTrue(exception);
	}
}
